<template>
	<view class="my-detail" v-if="loading" >
		
		<view style="height: 10px;"></view>
		<view class="cardBox">	
			<show-detail v-if="loading" :info="detailData" :type="releaseType" :lx="type" :info_title="$t('详情')"></show-detail>
		</view>
		
		<view class="cardBox">
			<ProductWHL  v-if="loading" :item="detailData" :type="type"></ProductWHL>
		</view>
		
		<!--  多文字详情内容  多详情图片  上传视频    布局放在详细信息 卡片 底下 -->
		<Info  v-if="loading" :detailData="detailData" :releaseType="releaseType" :type="type"></Info>
		
		
	</view>
</template>

<script>
	import {HTTP_REQUEST_URL,HTTP_IMG_UTL,IMAGE_URL} from "@/config/app";
	import showDetail from "@/components/showDetail.vue";
	import ProductWHL from '@/components/ProductWHL.vue';
	import Info from './Info.vue'
	
	export default {
		data() {
			return {
				//远程域名
				HTTP_IMG_UTL,
				HTTP_REQUEST_URL,
				IMAGE_URL,
				url: IMAGE_URL,

				loading: false,
				lang: getApp().globalData.lang,
				detailData: {},
				id: 0, 			// 商品id
				type: 1, 		// 1=推广，2=竞标
				
				releaseType: '',
				status: ''
			};
		},
		components: {
			showDetail,ProductWHL,Info
		},
		onLoad(option) {
			console.log(option);
			if(option){
				// this.releaseType = option.releaseType
				if(option.releaseType=='goods'){
					this.releaseType='order_info_goods';
				}else if(option.releaseType=='transport'){
					this.releaseType='order_info_transport';
				}else if(option.releaseType=='crossborder'){
					this.releaseType='order_info_crossborder';
				}
				console.log(this.releaseType);
				this.id = parseInt(option.id)
				this.type = parseInt(option.type)
				this.status = option.status
			}
			
			
			this.lang = this.$i18n.locale 
			
			this.getDetail()
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.$t("详情页")
			})
		},
		methods: {
			downLoadFile(url) {
				const that = this
				uni.showLoading({
					title:"download...",
					mask:true
				})
				console.log('下载链接', this.IMAGE_URL + url)
				var downloadTask = uni.downloadFile({
					url: that.IMAGE_URL + url,
					success(res) {
						uni.hideLoading()
						console.log('tempFilePath', res.tempFilePath)
						const tempFilePath = res.tempFilePath
						uni.openDocument({
							filePath: tempFilePath,
							showMenu: true,
							success: function(file) {
								console.log('file-success', file);
							}
						});
					},
				})
				downloadTask.onProgressUpdate(({progress,totalBytesWritten,totalBytesExpectedToWrite}) => {
					if(progress === 100){
						downloadTask.offProgressUpdate();
					}
				})
			},
			getDetail() {
				const that = this
				console.log(that.id);
				that.$u.api.order.getOrderDetail({
					id: that.id,
					lang:that.lang,
					status:0,
				}).then(res => {
					console.log(res)
					var img = ''
					
					if(res.orderInfo.type=='goods'){
						if((res.orderJoin.logo)&&(res.orderJoin.logo.length!=0)){
							img = res.orderJoin.logo[0].url
						}
						if(img==''){
							if((res.orderJoin.images)&&(res.orderJoin.images.length!=0)){
								img = res.orderJoin.images[0].url
							}
						}
					}else if(res.orderInfo.type=='transport'){
						if(res.orderInfo.release_info.release_type==1||(res.orderInfo.release_info.release_type==3&&res.orderInfo.release_info.human_type==2)){
							if((res.orderJoin.images)&&(res.orderJoin.images.length!=0)){
								img = res.orderJoin.images[0].url
							}
						}
						if(res.orderInfo.release_info.release_type==2||(res.orderInfo.release_info.release_type==3&&res.orderInfo.release_info.human_type==1)){
							if((res.orderInfo.release_info.images)&&(res.orderInfo.release_info.images.length!=0)){
								img = res.orderInfo.release_info.images[0].url
							}
						}
					}else if(res.orderInfo.type=='crossborder'){
						if((res.orderInfo.release_info.logo)&&(res.orderInfo.release_info.logo.length!=0)){
							img = res.orderInfo.release_info.logo[0].url
						}
						if(img==''){
							if((res.orderInfo.release_info.images)&&(res.orderInfo.release_info.images.length!=0)){
								img = res.orderInfo.release_info.images[0].url
							}
						}
					}
					
					console.log(img)
					
					//货物
					that.detailData.price=res.orderJoin.price
					that.detailData.price_unit=res.orderJoin.price_unit
					that.detailData.zj_price=res.orderJoin.zj_price
					
					if(that.releaseType=='order_info_goods'){
						that.detailData.hwdd=res.orderInfo.release_info.hwdd
						if(that.lang=='zh'){
							that.detailData.product_address=res.orderJoin.product_address.mergename
						}else{
							that.detailData.product_address=res.orderJoin.product_address.mergename_ru
						}
					}
					
					if(that.lang=='ru'){
						that.detailData.order_info_goods={
							name:res.orderJoin.product_ru,
							logo:img,
							goods_num:res.orderJoin.num,
							number_unit:res.orderJoin.number_unit,
						}
					}else{
						that.detailData.order_info_goods={
							name:res.orderJoin.product,
							logo:img,
							goods_num:res.orderJoin.num,
							number_unit:res.orderJoin.number_unit,
						}
					}
					
					
					
					if(!res.orderInfo.release_info.goods_weight){
						that.detailData.goods_weight=0
					}else{
						that.detailData.goods_weight=res.orderInfo.release_info.goods_weight
					}
					that.detailData.goods_volume=res.orderInfo.release_info.goods_volume
					
					
					
					if(that.releaseType=='order_info_transport'){
						that.detailData.is_express_price=''
					}else{
						that.detailData.is_express_price=res.orderInfo.release_info.is_express_price
					}
					
					
					if (res.orderInfo.release_info.release_type === '3') { // 人力少货，重量*价格
						that.detailData.price = res.orderJoin.price * res.orderJoin.product_weight
					} 
					
					if(res.orderInfo.release_info.release_type==1){
						that.detailData.goods_weight = res.orderJoin.product_weight
						that.detailData.goods_volume = res.orderJoin.product_volume
					}
					if(res.orderInfo.release_info.release_type==3){
						if(res.orderInfo.release_info.human_type==2){
							that.detailData.goods_weight = res.orderJoin.product_weight
							that.detailData.goods_volume = res.orderJoin.product_volume
						}
					}
					
					
					
					that.detailData.margin_price=res.orderInfo.release_info.margin_price
					that.detailData.margin_type=res.orderInfo.release_info.margin_type
					that.detailData.number_unit=res.orderJoin.number_unit
					that.detailData.number_unit_ru=res.orderJoin.number_unit_ru
					that.detailData.goods_l=res.orderJoin.goods_l
					that.detailData.goods_w=res.orderJoin.goods_w
					that.detailData.goods_h=res.orderJoin.goods_h
					
					
					that.detailData.content=res.orderJoin.con
					that.detailData.content_ru=res.orderJoin.con_ru
					
					
					//运输
					if(that.lang=='ru'){
						that.detailData.order_info_transport={
							name:res.orderJoin.product_ru,
							logo:img,
							goods_num:res.orderJoin.num,
							number_unit:res.orderJoin.number_unit,
						}
					}else{
						that.detailData.order_info_transport={
								name:res.orderJoin.product,
								logo:img,
								goods_num:res.orderJoin.num,
								number_unit:res.orderJoin.number_unit,
							}
						
					}
					that.detailData.hyd=res.orderInfo.release_info.hyd
					that.detailData.departure_address=res.orderJoin.product_address.area_name//装货地址
					that.detailData.shd=res.orderInfo.release_info.shd
					that.detailData.reach_address=res.orderJoin.reach_address.area_name//卸货地址
					that.detailData.send_goods_date=res.orderInfo.release_info.send_goods_date
					that.detailData.desire_speed=res.orderInfo.release_info.desire_speed
					that.detailData.is_topping=res.orderInfo.release_info.is_topping
					
					
					
					//跨境
					if(that.lang=='ru'){
						that.detailData.order_info_crossborder={
							name:res.orderJoin.product_ru?res.orderJoin.product_ru:res.orderInfo.release_info.goods_name_ru,
							logo:img,
							goods_num:res.orderInfo.release_info.goods_num,
							number_unit:res.orderInfo.release_info.number_unit_ru,
						}
					}else{
						that.detailData.order_info_crossborder={
								name:res.orderJoin.product?res.orderJoin.product:res.orderInfo.release_info.goods_name,
								logo:img,
								goods_num:res.orderInfo.release_info.goods_num,
								number_unit:res.orderInfo.release_info.number_unit,
							}
						
					}
					if(that.releaseType=='order_info_crossborder'){
					
						that.detailData.clearance=res.orderInfo.release_info.clearance
						that.detailData.is_express_price=res.orderInfo.release_info.is_express_price
						that.detailData.is_load_unload=res.orderInfo.release_info.is_load_unload
						that.detailData.is_warehouse=res.orderInfo.release_info.is_warehouse
					}
					
					that.detailData.createtime=res.orderInfo.createtime
					if(res.orderInfo.is_qrsh==1){
						that.detailData.completetime=res.orderInfo.updatetime
					}else{
						that.detailData.completetime=''
					}
					
					that.loading=true
				})

			}
		},
	}
</script>

<style lang="scss" scoped>
	.my-detail {
		background-color: #ffffff;
		padding-bottom: 160rpx;
	
		.cardBox {
			width: 90%;
			margin: 0 auto;
			box-shadow: 0 0 10px #ddd;
			background: #ddd;
			padding: 10rpx 20rpx;
			border-radius: 20rpx;
			background: #fff;
			margin-bottom: 20rpx;
			position: relative;
			&.yellow{
				background: #fefcf6;
			}
	
		}
	
		.newTitle {
			width: 90%;
			margin: 0 auto;
			font-weight: 600;
			padding-top: 40rpx;
			.icon{
				margin-left: 10rpx;
				transform: rotate(-90deg);
				font-weight: normal;
			}
		}
	}
</style>